package com.zerak.calendarviewlib;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
/**
 * 
 * @author Zerak Xirkiti 
 * @category www.zerak.biz
 *
 */
public class UyTextView extends TextView {

	public UyTextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context, attrs);
	}

	public UyTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context, attrs);
	}

	public UyTextView(Context context) {
		super(context);
		init(context, null);
	}

	private void init(Context mConetxt, AttributeSet attrs) {

		try {

			if (UyGlobal.uy_Typeface == null) {
				UyGlobal.uy_Typeface = Typeface.createFromAsset(
						mConetxt.getAssets(),UyGlobal.uyFontNameForAsset);
				this.setTypeface(UyGlobal.uy_Typeface);
			} else {
				this.setTypeface(UyGlobal.uy_Typeface);
			}
		} catch (Exception ex) {
			UyGlobal.uy_Typeface = Typeface.DEFAULT;
		}

		if (attrs != null) {
			int resouceId = attrs.getAttributeResourceValue(
					"http://schemas.android.com/apk/res/android", "text", 0);
			if (resouceId != 0) {
				try {
					setText(mConetxt.getResources().getString(resouceId));

				} catch (Exception ex) {

				}

			} else {
				String str = attrs.getAttributeValue(
						"http://schemas.android.com/apk/res/android", "text");
				if (str != null)
					setText(str);
			}
		}
	}

	public void setText(String str) {
		super.setText(UyGlobal.uyConvert.getUyPFStr(str));
	}

}
